﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InitSaleMasterForm.aspx.cs"
    Inherits="PSS.WebSite.SaleManage.InitSaleMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-splitter" vertical="true" style="width: 100%; height: 100%;">
        <div size="50%" showcollapsebutton="true">
            <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                <table>
                    <tr>
                        <td align="right">
                            单据编号：
                        </td>
                        <td style="width: 150px;" align="left">
                            <input id="DocNumber" class="mini-textbox" emptytext="请输入单据编号" style="width: 150px;"
                                onenter="onKeyEnter" />
                        </td>
                        <td align="right">
                            供应商：
                        </td>
                        <td style="width: 150px;" align="left">
                            <input id="CustomerId" class="mini-combobox" style="width: 150px;" valuefield="CustomerId"
                                textfield="CustomerName" />
                        </td>
                        <td style="width: 100px;">
                            <a class="mini-button" iconcls="icon-search" onclick="search()">查 询</a>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            日期：
                        </td>
                        <td style="width: 150px;" align="left">
                            <input id="DocDateFrom" style="width: 150px;" class="mini-datepicker" format="yyyy-MM-dd" />
                        </td>
                        <td align="right">
                            至：
                        </td>
                        <td style="width: 150px;" align="left">
                            <input id="DocDateEnd" style="width: 150px;" class="mini-datepicker" format="yyyy-MM-dd" />
                        </td>
                        <td style="width: 100px;">
                            <a class="mini-button" iconcls="icon-reset" onclick="reset()">重 置</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                <table style="width: 100%;">
                    <tr>
                        <td style="width: 100%;">
                            <a class="mini-button" id="add" iconcls="icon-add" onclick="add();" plain="true">添加</a>
                            <a class="mini-button" id="edit" iconcls="icon-edit" onclick="edit()" plain="true">编辑</a>
                            <a class="mini-button" iconcls="icon-remove" id="remove" onclick="remove()" plain="true">
                                删除</a> <span class="separator"></span><a class="mini-button" onclick="close()" iconcls="icon-close"
                                    plain="true">关闭</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="mini-fit">
                <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="InitSaleId"
                    sizelist="[10,20,50,100]" pagesize="20" borderstyle="border:0;" onselectionchanged="onSelectionChanged"
                    selectonload="true">
                    <div property="columns">
                        <div type="indexcolumn">
                        </div>
                        <div field="DocDate" width="90" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd">
                            单据日期
                        </div>
                        <div field="DocNumber" width="120" headeralign="center" allowsort="true">
                            单据编号
                        </div>
                        <div field="BusinessCategory" width="120" headeralign="center" allowsort="true" renderer="onBusinessCategoryRenderer">
                            业务类别
                        </div>
                        <div field="CustomerName" width="120" headeralign="center" allowsort="true">
                            客户
                        </div>
                        <div field="SalesAmount" width="100" headeralign="center" allowsort="true">
                            销售总金额
                        </div>
                        <div field="FoldAmount" width="100" headeralign="center" allowsort="true">
                            折扣后总金额
                        </div>
                        <div field="TheCollection" width="100" headeralign="center" allowsort="true">
                            已收款金额
                        </div>
                        <div field="Remark" width="120" headeralign="center" allowsort="false">
                            备注
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div size="50%" showcollapsebutton="true">
            <div class="mini-fit">
                <div id="grid2" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="InitSaleDetailId"
                    showfooter="false" borderstyle="border:0;">
                    <div property="columns">
                        <div type="indexcolumn">
                        </div>
                        <div field="GoodsCode" width="100px" headeralign="center">
                            商品编号
                        </div>
                        <div field="GoodsName" width="120px" headeralign="center">
                            商品名称
                        </div>
                        <div field="Specific" width="120px" headeralign="center">
                            规格型号
                        </div>
                        <div field="UnitName" width="80px" headeralign="center">
                            计量单位
                        </div>
                        <div field="StorageCode" width="80px" headeralign="center">
                            仓库编号
                        </div>
                        <div field="StorageName" width="80px" headeralign="center">
                            仓库名称
                        </div>
                        <div field="Qty" width="80px" headeralign="center">
                            数量
                        </div>
                        <div field="SalesPrice" width="80px" headeralign="center">
                            销售单价
                        </div>
                        <div field="DiscountRate" width="80px" headeralign="center" renderer="onDiscountRateRenderer">
                            折扣率
                        </div>
                        <div field="DeductionAmount" width="100px" headeralign="center">
                            折扣额
                        </div>
                        <div field="SalesAmount" width="100px" headeralign="center">
                            销售金额
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var now = new Date();
        var nowYear = now.getFullYear();
        var nowMonth = now.getMonth();
        var DocDateFrom = mini.get("DocDateFrom");
        DocDateFrom.setValue(new Date(nowYear, nowMonth, 1));
        var DocDateEnd = mini.get("DocDateEnd");
        DocDateEnd.setValue(new Date());
        var CustomerId = mini.get("CustomerId");
        CustomerId.setUrl("../Service/SetManageHandler.ashx?action=GetCustomerListByCombobox");
        var grid1 = mini.get("grid1");
        var grid2 = mini.get("grid2");
        grid1.setUrl("../Service/SaleManageHandler.ashx?action=GetInitSaleList");
        grid1.load({ DocDateFrom: DocDateFrom.getFormValue(), DocDateEnd: DocDateEnd.getFormValue() });
        function onSelectionChanged(e) {
            var grid = e.sender;
            var record = grid.getSelected();
            if (record) {
                grid2.setUrl("../Service/SaleManageHandler.ashx?action=GetInitSaleDetailList");
                grid2.load({ InitSaleId: record.InitSaleId });
            }
            else {
                grid2.setData([]);
            }
        }
        function search(e) {
            var DocNumber = mini.get("DocNumber").getValue();
            var CustomerId = mini.get("CustomerId").getValue();
            var DocDateFrom = DocDateFrom.getFormValue();
            var DocDateEnd = DocDateEnd.getFormValue();
            grid1.load({ DocNumber: DocNumber, CustomerId: CustomerId, DocDateFrom: DocDateFrom, DocDateEnd: DocDateEnd });
        }
        function onBusinessCategoryRenderer(e) {
            if (e.value == "2") { return "<span style=\"color: Red;\">退货</span>"; }
            else if (e.value == "1") { return "<span style=\"color: green;\">购货</span>"; }
        }
        grid1.on("drawcell", function (e) {
            var record = e.record,
        column = e.column,
        field = e.field,
        value = e.value;
            //设置行样式
            if (record.BusinessCategory == 2) {
                //e.rowCls = "myrow";
                e.cellStyle = "color:red;";
            }
        });

        function onKeyEnter(e) {
            search();
        }
        function reset(e) {
            mini.get("DocNumber").setValue("");
            mini.get("CustomerId").setValue("");
            DocDateFrom.setValue(new Date(nowYear, nowMonth, 1));
            DocDateEnd.setValue(new Date());
        }
        function add() {
            mini.open({
                url: "SaleManage/InitSaleInfoForm.aspx",
                title: "添加销货单", width: 875, height: 580,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid1.reload();
                }

            });
        }
        function edit() {
            var row = grid1.getSelected();
            if (row) {
                mini.open({
                    url: "SaleManage/InitSaleInfoForm.aspx",
                    title: "编辑销货单", width: 875, height: 580,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", InitSaleId: row.InitSaleId };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid1.reload();
                    }
                });

            } else {
                mini.alert("请选中一条记录!");
            }
        }
        function remove() {
            var row = grid1.getSelected();
            if (row) {
                mini.confirm("您确定要删除:" + row.DocNumber + "？", "确定？",
                        function (action) {
                            if (action == "ok") {
                                $.ajax({
                                    url: "../service/SaleManageHandler.ashx?action=RemoveInitSale&InitSaleId=" + row.InitSaleId,
                                    success: function (text) {
                                        grid1.reload();
                                    },
                                    error: function (jqXHR, textStatus, errorThrown) {
                                        alert(jqXHR.responseText);
                                    }
                                });
                            } else {
                                return false;
                            }
                        });

            } else {
                mini.alert("请选中一条记录!");
            }
        }
        function onDiscountRateRenderer(e) {
            return e.value + "%";
        }
        function CloseWindow(action) {
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function close() {
            CloseWindow("close");
        }
    </script>
</body>
</html>
